package main

import (
	"context"
	"fmt"
	"time"

	"github.com/coreos/etcd/clientv3"
)

func main() {
	var (
		conf   clientv3.Config
		client *clientv3.Client
		err    error
		kv     clientv3.KV
		rsp    *clientv3.PutResponse
		getRsp *clientv3.GetResponse
		delRsp *clientv3.DeleteResponse
	)
	//set conf
	conf = clientv3.Config{
		Endpoints:   []string{"127.0.0.1:2379"},
		DialTimeout: 5 * time.Second,
	}

	//new client
	if client, err = clientv3.New(conf); err != nil {
		fmt.Println(err)
		return
	}

	// put KV
	kv = clientv3.NewKV(client)
	if rsp, err = kv.Put(context.TODO(), "/user/local", "......."); err != nil {
		println(err)
	} else {
		println(rsp.Header.Revision)
	}

	//get
	if getRsp, err = kv.Get(context.TODO(), "/user/local"); err != nil {
		println(err)
	} else {
		println(getRsp.Kvs)
	}

	// delete
	if delRsp, err = kv.Delete(context.TODO(), "/user/local"); err != nil {
		println(err)
	} else {
		println(delRsp.PrevKvs)
	}
}
